/**
 * @file judgeDayInYear.c
 * @author liu6tot
 * @brief 计算某日在本年中是第几天
 * 定义结构体变量，把年、月、日等基本信息包含进来
 * @version 0.1
 * @date 2022-11-23
 *
 * @copyright Copyright (c) 2022
 *
 */
#include <stdio.h>
struct date
{
    int year; //成员变量
    int month;
    int day;
};
struct date mydate; //注意结构体的变量的定义
int main()
{
    int days;
    printf("Input year,month and day: ");
    /*注意使用.操作符访问成员变量*/
    scanf("%d%d%d", &mydate.year, &mydate.month, &mydate.day);
    /**
     * @brief
     * 如果是处在平面中的一天
     * 1月 days = mydate.day
     * 2月 days = mydate.day + 31
     * 3月 days = mydate.day + 31+ 28
     * 4月 days = mydate.day + 59 + 31
     * 5月 days = mydate.day + 90 + 30
     * 6月 days = mydate.day + 120 + 31
     * 7月 days = mydate.day + 151 + 30
     * 8月 days = mydate.day + 181 + 31
     * 9月 days = mydate.day + 212 + 31
     * 10月 days = mydate.day +243 + 30
     * 11月 days = mydate.day +273 + 31
     * 12月 days = mydate.day + 304 +30
     * 如果mydate.year是闰年&&mydate.month>=3,days+=1;
     */
    switch (mydate.month) //平年的算法
    {
    case 1:
        days = mydate.day + 0;
        break;
    case 2:
        days = mydate.day + 31;
        break;
    case 3:
        days = mydate.day + 31 + 28;
        break;
    case 4:
        days = mydate.day + 59 + 31;
        break;
    case 5:
        days = mydate.day + 90 + 30;
        break;
    case 6:
        days = mydate.day + 120 + 31;
        break;
    case 7:
        days = mydate.day + 151 + 30;
        break;
    case 8:
        days = mydate.day + 181 + 31;
        break;
    case 9:
        days = mydate.day + 212 + 31;
        break;
    case 10:
        days = mydate.day + 243 + 30;
        break;
    case 11:
        days = mydate.day + 273 + 31;
        break;
    case 12:
        days = mydate.day + 304 + 30;
        break;
    }
    //考虑闰年的情况
    //能被4整除，但是不能被100整除，但是却又被400整除
    if ((mydate.year % 4 == 0 && mydate.year % 100 != 0 && mydate.year % 400 == 0) && mydate.month >= 3)
    {
        days += 1;
    }
    //输出当前日期是一年中的第几天
    printf("\n%d/%d/%d是第%d天", mydate.year, mydate.month, mydate.day, days);
}
